package com.example.day10_zuoye.fragmnet;


import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.day10_zuoye.R;
import com.example.day10_zuoye.activity.LoginActivity;
import com.example.day10_zuoye.utils.SPUtils;

import java.util.Timer;
import java.util.TimerTask;

/**
 * A simple {@link Fragment} subclass.
 */
public class WelComeThreeFragment extends Fragment {

    ImageView imageView;
    TextView textView;

    private Timer timer;
    private int num = 5;


    public WelComeThreeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_wel_come_three, container, false);
        imageView = view.findViewById(R.id.iv);
        textView = view.findViewById(R.id.tv);
        Glide.with(getContext()).load("http://photocdn.sohu.com/20110716/Img313617599.jpg").into(imageView);
        initTimer();


        return view;
    }

    private void initTimer() {
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        textView.setText(num--+"");
                        if(num == 0){
                            timer.cancel();
                            Intent intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);


                            SPUtils.getInstance(getContext()).putString("go","1");
                        }
                    }
                });

            }
        },1000,1000);
    }

}
